
$(function() {
	// validate signup form on keyup and submit
	var validator = $("#form_add").validate({
		rules: {
			code: {
				required:true,
				remote: "contact.php?do=Customer.ajax_exist"
			},
			name: {
				required: true,
				minlength:2
			},
			email: {
				required: true,
				email: true
			},
			status: {
				required: true
			}
		},
		messages: {
			code: {
				required: "请输入编码",
				remote: jQuery.format("{0} 已经存在")
			},
			name: {
				required: "请输入简称",
				minlength: jQuery.format("请最少输入 {0} 个字符")
			},
			email: {
				required: "请输入正确格式的电子邮件",
				minlength: "请输入正确格式的电子邮件",
				remote: jQuery.format("{0} is already in use")
			},
			status: {
				required: "请选择一个状态"
			}
		},
		errorPlacement: function(label, element) {
			if (/^birthdate/.test(element[0].name)) {
				label.insertAfter("#birthdateYear");
			} else {
				label.insertAfter(element);
			}
		},
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}
	});
});